package GeneralObjects;
import java.util.ArrayList;

import utils.ByteTree;

/**
 * Representing an array of boolean elements  
 * @author Idan
 */
public class BooleanArray {
	private ArrayList<Boolean> boolArr;
	
	/**
	 * Constructor that creates a boolean array from its ByteTree representation
	 * @param bt ByteTree representation of a boolean array
	 * @throws Exception in case boolean elements could not be constructed from the ByteTree   
	 */
	public BooleanArray(ByteTree bt) throws Exception {
		boolArr = new ArrayList<Boolean>();
		byte[] data = bt.getData();
		for (int i=0; i<data.length; i++)
			boolArr.add(data[i]==1);
	}
	
	/**
	 * Constructor that creates a BooleanArray object from an array of booleans 
	 *@param b the array of booleans
 	 *@throws Exception in case boolean elements could not be constructed from the boolean array
 	 */
	public BooleanArray(boolean[] b) throws Exception
	{
		boolArr = new ArrayList<Boolean>();
		for (int i=0; i<b.length; i++)
			boolArr.add(b[i]);
	}
	
	public void addElement(boolean b) throws Exception
	{
		boolArr.add(b);
	}
	
	public boolean getElementForIndex(int i)
	{
		return boolArr.get(i);
	}
	
	public int getArraySize()
	{
		return boolArr.size();
	}
	
	public String toString() {
		String s = "";
		for (int i=0; i<boolArr.size(); i++)
			s += boolArr.get(i).toString()+"\n";
		return s;
	}
}
